
//
//  NewsView.m
//  yonghu
//
//  Created by 浪尖渝力 on 2018/2/5.
//  Copyright © 2018年 com.DJS. All rights reserved.
//

#import "NewsView.h"
#import "NewsTableViewCell.h"
@implementation NewsView
-(void)creatView{
    self.backgroundColor=_LightGrey;
    
    _tableView=[BaseTableView new];
    [self addSubview:_tableView];
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.top.mas_equalTo(NAV_HEIGHT);
    }];
    _tableView.backgroundColor=_LightGrey;
    _tableView.delegate=self;
    _tableView.dataSource=self;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    
    return _tableArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NewsTableViewCell *cell=[[NewsTableViewCell alloc] init];
    
    cell.dic=_tableArr[indexPath.row];
    [cell creatView];
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 160;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *dic=_tableArr[indexPath.row];
    NSNumber *mu_id=[dic objectForKey:@"mu_id"];
    NSNumber *mu_status=[dic objectForKey:@"mu_status"];
    if (mu_status.integerValue==0) {
        NSDictionary *userDic = [NSKeyedUnarchiver unarchiveObjectWithFile:_userModelFile];
        NSString *token=[userDic objectForKey:@"token"];
        NSNumber *waiter_id1=[userDic objectForKey:@"user_id"];
        NSString *user_id=[NSString stringWithFormat:@"%@",waiter_id1];
        NSDictionary *dic2=[NSDictionary dictionaryWithObjectsAndKeys:user_id,@"user_id",[NSString stringWithFormat:@"%@",mu_id],@"mu_id",token,@"token",@"0",@"user_role", nil];
        [ZQTools AFNPostDataUrl:@"api/center/change_message_status" Dict:dic2 andTableView:nil andViewController:self.viewController andSuccessBlock:^(id responseObject) {
            NSMutableDictionary *typeDic=[NSMutableDictionary dictionaryWithDictionary:dic];
            [typeDic setValue:@"1" forKey:@"mu_status"];
            [_tableArr replaceObjectAtIndex:indexPath.row withObject:typeDic];
            [_tableView reloadData];
            
        } anderrorBlock:nil];
    }
}


@end
